package maxSum;

import java.util.List;
import java.util.Stack;

public class Solution {
    public int maxSum(int[] nums) {
        int max = -1;
        for (int i = 0; i < nums.length; i++) {
            for (int j = i+1; j < nums.length; j++) {
                if(check(nums[i],nums[j])){
                    max = Math.max(nums[i],nums[j]);
                }
            }
        }
        return max;
    }
    private int getMax(int a){
        int ans = 0;
        while(a>0){
            ans = Math.max(ans,a%10);
            a/=10;
        }
        return ans;
    }
    private boolean check(int a,int b){
        return getMax(a) == getMax(b);
    }
      public class ListNode {
         int val;
         ListNode next;
          ListNode() {}
     ListNode(int val) { this.val = val; }
         ListNode(int val, ListNode next) { this.val = val; this.next = next; }
     }


    public ListNode doubleIt(ListNode head) {
        Stack<ListNode> stack = new Stack<>();
        ListNode p = head;
        while (p!=null){
            stack.add(p);
            p = p.next;
        }
        int t = 0;
        while (!stack.isEmpty()){
            ListNode n = stack.pop();
            int num = n.val*2+t;
            n.val = num%10;
            t = num/10;
        }
        if(t!=0){
            ListNode ans = new ListNode(t);
            ans.next = head;
            return ans;
        }
        return head;
    }
}
